﻿
using System;
using Autodesk.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.ApplicationServices;
using Cad.Infrastructure.View;

[assembly: Autodesk.AutoCAD.Runtime.ExtensionApplication(typeof(Cad.Infrastructure.CadInitialize))]
namespace Cad.Infrastructure
{
    public class CadInitialize : Autodesk.AutoCAD.Runtime.IExtensionApplication
    {
        public void Initialize()
        {
            //加载后初始化的程序放在这里 这样程序一加载DLL文件就会执行
            Document doc = Application.DocumentManager.MdiActiveDocument;
            doc.Editor.WriteMessage("\n加载程序中...........\n");

            Application.Idle += Application_Idle;

        }

        private void Application_Idle(object sender, EventArgs e)
        {

            var ribbonControl = Autodesk.Windows.ComponentManager.Ribbon;

            if (ribbonControl != null)
            {
                Application.SystemVariableChanged += (o, e1) =>
                {
                    if (e1.Name.ToUpper() == "WSCURRENT")
                    {
                        //加载菜单栏需
                        AddMenu();
                    }
                };
                Application.Idle -= Application_Idle;
            }

         
        }

        public void Terminate()
        {
            throw new NotImplementedException();
        }


        public void AddMenu()
        {
            //Document doc = Application.DocumentManager.MdiActiveDocument;
            //doc.Editor.WriteMessage("添加菜单栏成功！>>>>>>>>>>>>>>");

            RibbonControl ribbon = ComponentManager.Ribbon;
            RibbonTab tab = new RibbonTab();
            tab.Title = "我的界面";
            tab.Id = "Id";
            ribbon.Tabs.Add(tab);
            //默认选中
            tab.IsActive = true;
            RibbonPanelSource source = tab.AddPanel("绘图");
            source.Items.Add(new MyRibbonButton("直线", "直线"));
            source.Items.Add(new MyRibbonButton("圆弧", "圆弧"));
            source.Items.Add(new MyRibbonButton("扇形", "扇形"));

        }


    }
}
